﻿using System.Transactions;
using AutoClub.Core.Dao.Support;
using AutoClub.Core.Domain.Dao;
using AutoClub.Helper.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace AutoClub.Core.Tests
{
    /// <summary>
    /// Base test class for all repo unit tests
    /// </summary>
    [TestClass]
    public abstract class BaseRepoTest
    {
        #region Fields

        protected MockRepository mockRepositoryInstance;
        protected TransactionScope transaction;
        protected ModelHelper modelHelper = new ModelHelper();
        protected IUnitOfWork uof;

        #endregion

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext)
        {

        }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup()]
        public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public virtual void MyTestInitialize()
        {
            this.mockRepositoryInstance = new MockRepository();
            transaction = new TransactionScope(TransactionScopeOption.RequiresNew);
            this.uof = UnitOfWorkFactory.CreateNew();

        }

        // Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public virtual void MyTestCleanup()
        {
            this.mockRepositoryInstance = null;
            this.transaction.Dispose();
            this.uof.Dispose();
        }

        #endregion
    }
}
